#include <bits/stdc++.h>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=5e4+100;
typedef int LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
char s1[maxn],s2[maxn];
char S[maxn*2];
LL d[maxn*2];
inline void pre(const char* s,const LL n){
    memset(d,0,sizeof(d));
    LL i=1,j=0;
    while(i<n){
        if(s[i]==s[j]){
            d[i++]=++j;
        }
        else{
            if(j) j=d[j-1];
            else i++;
        }
    }
}
inline void solve(const char* s,LL len,LL limit1,LL limit2){
    LL n=len;
    pre(s,n);
    if(d[n-1]==0){
        cout<<"0"<<endl;
    }
    else{
        LL ans=0;LL pos=n-1;
        while(d[pos]>limit1||d[pos]>limit2){
            pos=d[pos-1];
        }
        for(int i=0;i<d[pos];i++){
            cout<<s[i];
        }cout<<" "<<d[pos]<<endl;
    }
}
int main(void){
    while(cin>>s1>>s2){
        LL n=strlen(s1);LL m=strlen(s2);
        for(int i=0;i<n;i++) S[i]=s1[i];
        for(int i=n,j=0;i<n+m&&j<m;i++,j++) S[i]=s2[j];
        solve(S,n+m,n,m);
    }
   	return 0;
}
